<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!-- 猜数字游戏，设定次数，最多猜8次 -->
  <script>
    function getNum(m, n) {
      return Math.floor(Math.random() * (m - n + 1)) + n
    }
    let result = getNum(10, 1)
    document.write(result)
    for (let i = 1; i <= 8; i++) {
      let num = +prompt('请输入一个数字')
      if (num > result) {
        alert('猜大了哟')
      }
      if (num < result) {
        alert('猜小了哟')
      }
      if (num === result) {
        alert('niubi,猜对了')
        break
      }
    }
  </script>
</body>

</html>